package com.company.management.utils;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class JsonData {
    // 0 success, 1 proccssing, -1 fail
    private Integer code;
    //data
    private Object data;
    //information
    private String msg;

    public JsonData(Integer code, Object data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public JsonData(ResultCode resultCode, Object data) {
        this.code = resultCode.code;
        this.msg = resultCode.msg;
        this.data = data;
    }

    public JsonData(ResultCode resultCode, String msg, Object data) {
        this.code = resultCode.code;
        this.msg = resultCode.msg + "," + msg;
        this.data = data;
    }
    public static JsonData buildSuccess(){
        return new JsonData(ResultCode.SUCCESS, null, null);
    }
    public static JsonData buildSuccess(Object data){
        return new JsonData(ResultCode.SUCCESS, data);
    }

    public static JsonData buildWithData(ResultCode resultCode, Object data) {
        return new JsonData(resultCode, data);
    }

    public static JsonData buildWithData(ResultCode resultCode, String msg, Object data) {
        return new JsonData(resultCode, msg, data);
    }

    public static JsonData create(ResultCode resultCode) {
        return new JsonData(resultCode, null);
    }

    public static JsonData create(ResultCode resultCode, String msg) {
        return new JsonData(resultCode, msg, null);
    }
    /**
     *
     * @param msg
     * @return
     */
    public static JsonData buildError(String msg){
        return new JsonData(-1, null, msg);
    }

    /**
     * 
     * @param code
     * @param msg
     * @return
     */
    public static JsonData buildError(Integer code, String msg){
        return new JsonData(code, null, msg);
    }
}
